<?php

class CrawlController extends Controller
{
	public function actions()
	{

	}

	public function actionDiandian()
	{
		$q = Yii::app()->request->getParam('q');
		$p = intval(Yii::app()->request->getParam('p'));
		$q = $q ? $q : "美女";
		$p = $p ? $p : 1;
		/*if(!$q){
			$q = "美女";
		}
		if(!$p){
			$p = 1;
		}
		*/
		$url = Yii::app()->params['crawlUrl']['diandian'] . urlencode($q) . '?page=' . $p;
		$content = Yii::app()->curl->get($url);

		//Faint!! php中缺少php-xml(php-dom)扩展,导致没法使用phpQuery.
		//disable yii autoload, cause it is not compatible with phpQuery
		spl_autoload_unregister(array('YiiBase', 'autoload')); 
		//Yii::import('ext.tools.phpQuery');
		include_once( dirname(__FILE__). '/../shared/tools/phpQuery.php');
		$doc = phpQuery::newDocumentHTML($content);
		$els = pq('img[data-lazyload="false"]');
		phpQuery::$document = array();
		spl_autoload_register(array('YiiBase', 'autoload'));

		echo count($els);
		//echo $content;


	}
}